import React from 'react';
import Main from './lalyout'
import Login from './views/login';
import NotFound from '@/views/notfound';
import {Route,Switch,Redirect} from 'react-router-dom'
import {connect} from 'react-redux'
import {loginSuccess} from './action/action'
function App(props) {
  let saveData = localStorage.getItem('userInfo') || sessionStorage.getItem('userInfo')
  console.log(saveData);
  !props.user.userInfo && saveData && props.loginSuccess(JSON.parse(saveData))
  return (
    <div className="App" style={{height:'100vh'}}>
        <Switch>
            <Route path='/login' render={()=><Login/>}/>
            <Route path='/main' render={()=>{
              if(saveData || props.user.userInfo){
                return <Main />
              }
              return <Redirect to='/login' />
            }}/>
            <Redirect from='/' to='main'/>
            <Route path='*' component={NotFound}/>
        </Switch>
    </div>
  );
}

export default connect(state=>state,{loginSuccess})(App);
